const e = require('express')
const { token } = require('../db')

module.exports = async function(req, res, next){
    const noToken = ["/goods","/users/login","/users/admin","/users/register"]
    if(noToken.includes(req.url)){
        next()
    }else if (req.headers['authorization']) {
        const reqToken = req.headers['authorization']
        const resData = await token.find({token:reqToken})
        if(resData.length > 0) {
            next()
        }else{
            res.json({code:0,msg: "身份已过期，请登录"})
        }
    }else{
        res.json({code:0,msg: "请登录"})
    }
    

}